import { call, put, takeLatest } from 'redux-saga/effects';
import { REMOVE_TYPE,removeType } from '../actions/types.action';
import Message from '../components/SimpleLayer/Message';
import API from '../services';
 
function showErr(content){
	Message.error({
		top:'6px',
		width:'300',
		content,
		delayAutoClose:2000,
		yes:false
	});
}
function* remove(action) {
   try {
      const res = yield call(API.RemoveType, action.data);
  		if (res.success) {
  			yield put(removeType(action.data.id));
        Message.info({
          delayAutoClose:1200,
          top:'6px',
          width:300,
          content:'删除成功！'
        });
  		}else{
  			showErr(res.result);
  		}
   } catch (e) {
      	showErr(e.message);
   }
}

function* RemoveTypeSaga() {
  yield takeLatest(REMOVE_TYPE, remove);
}

export default RemoveTypeSaga;

